﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Common.Helpers/RandomHelper 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       RandomHelper
* 创建时间：  2025/6/4 11:29:25
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion 
using SixLabors.ImageSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Common.Helpers
{
    public class RandomHelper
    {
        //获得随机颜色
        public static Color GetRandomColor()
        {
            Random RandomNum_First = new Random(RandomExtensions.GetRandomSeed());
            //System.Threading.Thread.Sleep(RandomNum_First.Next(50));
            Random RandomNum_Sencond = new Random(RandomExtensions.GetRandomSeed());
            //为了在白色背景上显示，尽量生成深色
            int int_Red = RandomNum_First.Next(256);
            int int_Green = RandomNum_Sencond.Next(256);
            int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - (int_Red + int_Green);
            int_Blue = (int_Blue > 255) ? 255 : int_Blue;
            return Color.FromRgb((byte)int_Red, (byte)int_Green, (byte)int_Blue);
        }

        //获得随机颜色
        public static Color GetRandomBackGroundColor()
        {
            Random RandomNum_First = new Random(RandomExtensions.GetRandomSeed());
            Random RandomNum_Sencond = new Random(RandomExtensions.GetRandomSeed());
            //为了在白色背景上显示，尽量生成深色
            int int_Red = RandomNum_First.Next(100, 256);
            int int_Green = RandomNum_Sencond.Next(100, 256);
            int int_Blue = RandomNum_Sencond.Next(100, 256);
            int_Blue = (int_Red + int_Green < 400) ? 255 : int_Blue;
            int_Blue = (int_Blue > 255) ? 255 : int_Blue;
            return Color.FromRgb((byte)int_Red, (byte)int_Green, (byte)int_Blue);
        }

        /// <summary>
        /// 获取随机字符
        /// </summary>
        /// <param name="intSize"></param>
        /// <returns></returns>
        static public string GetRandomCode(int intSize)
        {
            string strRtn = "";

            Random Rnd = new Random();

            char[] ocdChars = "123456789ABCDEFGHJKMNPQRSTUVWXYZ".ToCharArray();
            for (int i = 0; i < intSize; i++)
            {
                strRtn += ocdChars[Rnd.Next(0, ocdChars.Length)].ToString();
            }

            return strRtn;
        }
        /// <summary>
        /// 获取随机数字
        /// </summary>
        /// <param name="intSize"></param>
        /// <returns></returns>
        static public string GetRandomNumber(int intSize)
        {
            string strRtn = "";
            char[] ocdChars = "0123456789".ToCharArray();
            for (int i = 0; i < intSize; i++)
            {
                strRtn += ocdChars[new Random(RandomExtensions.GetRandomSeed()).Next(i > 0 ? 0 : 1, ocdChars.Length)].ToString();
            }
            return strRtn;
        }

        /// <summary>
        /// 获取随机字母
        /// </summary>
        /// <param name="intSize"></param>
        /// <returns></returns>
        static public string GetRandomLetter(int intSize)
        {
            string strRtn = "";
            char[] ocdChars = "abcdefghjkmnpqrstuvwxyz".ToCharArray();
            for (int i = 0; i < intSize; i++)
            {
                strRtn += ocdChars[new Random(RandomExtensions.GetRandomSeed()).Next(0, ocdChars.Length)].ToString();
            }
            return strRtn;
        }

    }
}
